<?php
/**
 * Template Name: About - News Listing
 * Description: The news listing page for About
 *
 * @package ManterRealty
 * 
 */

get_header(); ?>
		
        <div class="kc_wrap kc_section">
        	<?php if ( have_posts() ) : ?>
            	<?php while ( have_posts() ) : the_post(); ?>
					<div class="cols cols_2cols about_cols about_cols_2cols clearfix">
                   
                    	<div class="col col_1">
                        	<div class="col_pad">
                            
                            	<div class="sec_nav_wrap">
									<div class="sec_nav_pad">
										<ul class="sec_nav">
										<?php
											// declare custom fields before entering deeper loops
											$vals = get_post_custom_values('news_hero',$page->ID);
											$heroImage = wp_get_attachment_image_src($vals[0], 'full');
											
											$parent = 38; // About
											$args=array(
											  'child_of' => $parent
											);
											$pages1 = get_pages($args);  
											if ($pages1) {
											  $pageids = array();
											  foreach ($pages1 as $page) {
												$pageids[]= $page->ID;
											  }
											
											  $args=array(
												'title_li' => '',
												'include' =>  $parent . ',' . implode(",", $pageids)
											  );
											  wp_list_pages($args);
											}
										?> 
										</ul>
									</div>
                                </div>
                                
                                <div class="callout_wrap">
                                	<div class="callout_pad">
                                    	
                                    </div>
                                </div>
                                
                            </div>
                        </div>
                    	
                        <div class="col col_2">
							<?php 
                            	echo '<div class="about_landing_intro clearfix">';
									echo('<img class="" src="'.$heroImage[0].'" />');
									echo('<h1>');
										the_title();
									echo('</h1>');
									the_content();
								echo '</div>';
								
								
								
								
                            ?>
							<div class="news_listing_wrap">
								
								<ul class="news_listing">
									<?php
										$thisSection = $post->ID;
										$sectionChildren = get_pages('child_of='.$thisSection.'&parent='.$thisSection.'&sort_column=menu_order&sort_order=asc');
										
										
										
										foreach($sectionChildren as $newsItem) {
											
											$vals = get_post_custom_values('is_external',$newsItem->ID);
											$isExternal = $vals[0];
											
											$newsItemTitle = get_the_title($newsItem->ID);
											$newsItemLink = get_permalink($newsItem->ID);
											$newsItemTarget = 'target="_self"';
											$newsItemExternalClass = '';
											$newsItemExternalTitle = '';
											
											if($isExternal) { 
												$vals = get_post_custom_values('external_link',$newsItem->ID); 
												$newsItemLink = $vals[0];
												$newsItemTarget = 'target="_blank"';
												$newsItemExternalClass = ' external ';
												$newsItemExternalTitle = ' title="Opens in new window" ';
											}
											
											$newsItemContent = substr(get_post($newsItem->ID)->post_content,0, 150).'...';
											
											echo('<li>');
												echo('<div class="listing_item">');
													 echo('<a class="listing_item_title'.$newsItemExternalClass.'" href="'.$newsItemLink.'" '.$newsItemTarget.$newsItemExternalTitle.'>'.$newsItemTitle.'</a>');
													 echo('<div class="listing_item_content">'.$newsItemContent.'</div>'); 
												echo('</div>');
											echo('</li>');
											
										}
									?>
								</ul>
								
							</div>
                        </div>
						
                    </div>
				<?php endwhile; ?>
             <?php endif; ?>
        </div>

<?php get_footer(); ?>